Main Raster Functions
FAIB_FC_TO_RASTER
Description:
This function convert an existing Postgres feature class table to a Raster.
The output raster will align with BC Raster Grid standard and be in BC Albers (SRID:3005) projection.
Assumptions & Cautionary Notes:
If output raster already exists it will be dropped then recreated with the new raster from this function - be careful!!
The funtion will automatically generate a VAT to apply to the output raster if no VAT is supplied and the valFld is Character type. This auto generated VAT will have the name of the output Raster with _VAT tagged to the end. If this object already exists in the Database it will be dropped and overwritten. Handle with Care.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| Required Parameters | |||
| fc | VARCHAR | N/A | Source feature class table |
| valFld | VARCHAR | N/A | The value field in the source feature class to rasterize on if Numeric type. If no VAT is supplied and this field is Character type then a VAT will be generated and applied to the output raster. If a VAT is supplied this field must exist/join to the VAT where the VAL column from the VAT will be applied to the output raster |
| outRaster | VARCHAR | N/A | The name of the output Raster |
| Optional Parameters | |||
| vat | VARCHAR | NULL | The value attribute table to apply to output raster values, if applicable. VAT must have column named VAL and a columun that joins to to valFld. If no VAT is supplied (NULL) and the valFld is Character type then a VAT will be generated on the fly and applied to the output raster. The autogenerated VAT will be named the same as the outRaster with _VAT on the end. |
| rastSize | NUMERIC | 100 | The size of raster pixels |
| rastPixType | VARCHAR | 32BF | The output raster pixel data type |
| noData | NUMERIC | 0 | NoData value in output raster |
| tile | BOOLEAN | FALSE | Whether to tile the output raster |
Usage & Examples:
Create a raster from a vector table using an integer (number) field to define output values.
Create a raster from a vector tagble using a character field. A VAT is not supplied to map the output raster values and the function will create one on the fly and apply the values to the output raster. The created VAT will have the name of the output with _VAT tagged onto it.
Create a raster from a vector table using VAT to define the output values. The VAT must have a VAL column that defines the output values and must link to the VAT with the valFld argument provided (TSA_NAME in the example)
SELECT FAIB_FC_TO_RASTER(
'TSA_CLIP',
'TSA_NAME',
'TSA_CLIP_RASTER_NAMEFLD_FROMVAT',
'TSA_CLIP_RASTER_NAMEFLD_VATEXAMPLE'
) FAIB_RASTER_CLIP
Description:
This function will clip an existing raster by the geometry that you supply to it. The geometry can be a select GEOMETRY from another feature class table in Postgres. This function is overloaded and will also accept a WKT Polygon reprsentation to clip by. See examples.
The output raster will align with BC Raster Grid standard.
Assumptions & Cautionary Notes:
The function assumes that the source Raster is in BC Albers projection (SRID: 3005).
If output raster already exists it will be dropped then recreated with the new raster from this function - be careful!!
Implementation:
This is an overloaded function - there are 2 different ways to execute this function. Same function name call but you can use either a text Polygon Constructor or a Geometry to define the Area of Interest - drawPoly
Note: drawPoly must be a text Polygon Constructor. PostGIS Well Known Text
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| Required Parameters | |||
| outRaster | VARCHAR | N/A | Output Raster Name |
| srcRaster | VARCHAR | N/A | The source Raster to clip from |
| clipper | GEOMETRY or TEXT WKT Polygon | ’*’ | The Geometry to clip the source Raster by or a WKT Polygon text |
Usage & Examples:
Clip a raster using a single geometry (returned from subquery against vector table)
SELECT FAIB_RASTER_CLIP(
'BEC_TSA_EXTENT_RASTER_TSA27',
'BEC_TSA_EXTENT_RASTER',
(SELECT WKB_GEOMETRY FROM TSA_CLIP WHERE TSA_NUMBER = '27')
)Clip a raster using multiple geometries (returned from subquery against vector table)
SELECT FAIB_RASTER_CLIP(
'BEC_TSA_EXTENT_RASTER_TSA270111',
'BEC_TSA_EXTENT_RASTER',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE TSA_NUMBER IN ('27', '01', '11'))
) FAIB_RASTER_FROM_VECTOR
Description:
This function is designed to generate a raster from a source vector table within an area of interest (drawPoly).
The area of interest can be a WGS 84 Well Known Text Polygon constructor (as would be created by a use in the CLUS Caribou App) or can be a Geometry object supplied by a query to another vector table.
The function allows you to generate a mask (1 value) raster output or generate values using a Numeric field from the vector source or with a Value Attribute Table.
You can further supply a where clause to filter what features from the source vector table that you would like to have included in the output raster.
See examples for the possibilities.
The output raster will align with BC Raster Grid standard.
Assumptions & Cautionary Notes:
The function assumes that the source Raster is in BC Albers projection (SRID: 3005).
If using a WKT Text Polygon as the drawPoly, it must be composed with coordinates in WGS 84 (SRID:4326)
If output raster already exists it will be dropped then recreated with the new raster from this function - be careful!!
If including a whereClause with enclosed strings in the criteria you must put a space at the end to enable proper quote embedding.
For example: whereClause:=‘ZONE_ALL LIKE’‘ESSF%’’ ’ (NOT - whereClause:=‘ZONE_ALL LIKE’‘ESSF%’’’)
Implementation:
This is an overloaded function - there are 2 different ways to execute this function. Same function name call but you can use either a text Polygon Constructor or a Geometry to define the Area of Interest - drawPoly
Note: drawPoly must be a text Polygon Constructor.
PostGIS Well Known Text
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| Required Parameters | |||
| outRaster | VARCHAR | N/A | Output Raster Name |
| drawPoly | TEXT (WKT Polygon) or GEOMETRY | N/A | The area of interest, represented as a WKT Polygon text string or a Geometry |
| srcVect | VARCHAR | N/A | The source vector table to generate the raster from |
| Optional Parameters | |||
| whereClause | VARCHAR | ’*’ | A Where clause to define what we want to include in the output from the source, within the area of interest |
| vatFld | VARCHAR | NULL | The field in the source vector and VAT to join to |
| vat | VARCHAR | NULL | The name of the VAT |
| mask | BOOLEAN | FALSE | Whether to Mask the output. Mask will create an output with values of 1 where criteria met, within AOI. False will retain values from VAT |
| rastSize | NUMERIC | 100 | Size of output raster cells |
| rastPixType | VARCHAR | 32BF | Pixel type of output raster |
| noData | NUMERIC | 0 | No Data value |
| tile | BOOLEAN | False | Whether to tile the ouptut raster |
Usage & Examples:
Examples using a WKT Polygon for AOI
Generate an output raster with a WKT Polygon using a Character field. VAT is automatically generated and applied to output. All values (*) are retained in the output.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_NOVAT_CHARFIELD',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_ZONE_CLIP',
mask:=FALSE,
whereClause:='*',
vatFld:='ZONE_ALL'
)Generate an output raster with a WKT Polygon using the VAT from the above example. Use a where clause to select values based on a selection from the associated VAT.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_VAT_FILTER',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_ZONE_CLIP',
mask:=FALSE,
whereClause:='ZONE_ALL LIKE ''ESSF%'' ',
vatFld:='ZONE_ALL',
vat:='BEC_ZONE_CLIP_RASTER_NOVAT_CHARFIELD_VAT'
)Generate an output raster with a WKT Polygon using the VAT from the above example. Use a where clause to select values based on a selection from the associated VAT but Mask the output.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_VAT_FILTER_MASK',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_ZONE_CLIP',
mask:=TRUE,
whereClause:='ZONE_ALL LIKE ''ESSF%'' ',
vatFld:='ZONE_ALL',
vat:='BEC_ZONE_CLIP_RASTER_NOVAT_CHARFIELD_VAT'
)Generate an output raster with a WKT Polygon and Mask the output. All values (*) are retained in the output.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_MASK_ALL',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_ZONE_CLIP',
mask:=TRUE
)Examples using a Geometry for AOI
Generate an output raster with a Geometry as AOI with a Character field for rasterizing. A VAT will automatically be generated with the name of the output raster with _VAT tagged on the end. Include all features within the AOI using the wildcard * whereClause.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_FROMGEOM_NOVAT_CHARFIELD',
(SELECT WKB_GEOMETRY FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE 'REV%'),
'BEC_ZONE_CLIP',
mask:=FALSE,
whereClause:='*',
vatFld:='ZONE_ALL'
)Generate an output raster with a Geometry as AOI (multiple geometries unioned) with a VAT lookup and whereClause to filter the output.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_FROMGEOM_VAT_FILTER',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) IN ('OKANAGAN TSA', 'ROBSON VALLEY TSA')),
'BEC_ZONE_CLIP',
mask:=FALSE,
whereClause:='ZONE_ALL LIKE ''ESSF%'' OR ZONE_ALL LIKE ''ICH%'' ',
vatFld:='ZONE_ALL',
vat:= 'BEC_ZONE_CLIP_RASTER_FROMGEOM_NOVAT_CHARFIELD_VAT'
)Generate an output raster with a Geometry as AOI (multiple geometries unioned) with a VAT lookup and whereClause to filter the output. Mask the output.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_FROMGEOM_VAT_FILTER',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) IN ('OKANAGAN TSA', 'ROBSON VALLEY TSA')),
'BEC_ZONE_CLIP',
mask:=TRUE,
whereClause:='ZONE_ALL LIKE ''ESSF%'' OR ZONE_ALL LIKE ''ICH%'' ',
vatFld:='ZONE_ALL',
vat:= 'BEC_ZONE_CLIP_RASTER_FROMGEOM_NOVAT_CHARFIELD_VAT'
)Generate an output raster with a Geometry as AOI with and Mask the entire output area.
SELECT FAIB_RASTER_FROM_VECTOR(
'BEC_ZONE_CLIP_RASTER_FROMGEOM_MASK_ALL',
(SELECT WKB_GEOMETRY FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE 'REVEL%'),
'BEC_ZONE_CLIP',
mask:=TRUE,
whereClause:='*'
)FAIB_RASTER_FROM_RASTER
Description:
This function is designed to generate a raster from a existing source raster within an area of interest (drawPoly).
The area of interest can be a WGS 84 Well Known Text Polygon constructor (as would be created by a use in the CLUS Caribou App) or can be a Geometry object supplied by a query to another vector table.
The function allows you to generate a mask (1 value) raster output or generate values using a Value Attribute Table (VAT) to map the output values.
You can further supply a where clause to filter what features from the source vector table that you would like to have included in the output raster. The where clause can be related to the VAT that you supply to filter for values or you can use a list of raster numeric values or a range of values or a combination therof. (1, 2, 3) or (1, 2, 3, 10-40, 50-90) or (1-10) etc.
See examples for the possibilities.
The output raster will align with BC Raster Grid standard.
Assumptions & Cautionary Notes:
The function assumes that the source Raster is in BC Albers projection (SRID: 3005).
If using a WKT Text Polygon as the drawPoly, it must be composed with coordinates in WGS 84 (SRID:4326)
If output raster already exists it will be dropped then recreated with the new raster from this function - be careful!!
If including a whereClause with enclosed strings in the criteria you must put a space at the end to enable proper quote embedding.
For example: whereClause:=‘ZONE_ALL LIKE’‘ESSF%’’ ’ (NOT - whereClause:=‘ZONE_ALL LIKE’‘ESSF%’’’)
Implementation:
This is an overloaded function - there are 2 different ways to execute this function. Same function name call but you can use either a text Polygon Constructor or a Geometry to define the Area of Interest - drawPoly
FAIB_RASTER_FROM_RASTER(
outRaster VARCHAR,
drawPoly TEXT,
srcRast VARCHAR,
rastVal VARCHAR DEFAULT '*',
rastVAT VARCHAR DEFAULT NULL,
mask BOOLEAN DEFAULT FALSE,
rastSize NUMERIC DEFAULT 100.00,
rastPixType VARCHAR DEFAULT '32BF',
noData NUMERIC DEFAULT 0,
tile BOOLEAN DEFAULT False
) RETURNS VOIDNote: drawPoly must be a text Polygon Constructor.
PostGIS Well Known Text
FAIB_RASTER_FROM_RASTER(
outRaster VARCHAR,
drawPoly GEOMETRY,
srcRast VARCHAR,
rastVal VARCHAR DEFAULT '*',
rastVAT VARCHAR DEFAULT NULL,
mask BOOLEAN DEFAULT FALSE,
rastSize NUMERIC DEFAULT 100.00,
rastPixType VARCHAR DEFAULT '32BF',
noData NUMERIC DEFAULT 0,
tile BOOLEAN DEFAULT False
) RETURNS VOIDParameters:
| Name | Type | Default | Description |
|---|---|---|---|
| Required Parameters | |||
| outRaster | VARCHAR | N/A | Output Raster Name |
| drawPoly | TEXT (WKT Polygon) or GEOMETRY | N/A | The area of interest, represented as a WKT Polygon text string or a Geometry |
| srcRast | VARCHAR | N/A | The source raster to generate the raster from |
| Optional Parameters | |||
| rastVal | VARCHAR | ’*’ | The value or list of values from the source raster to include in the output. If using a VAT you can form this parameter as a Where clause to define what we want to include in the output from the source, within the area of interest |
| rastVAT | VARCHAR | NULL | The VAT to apply for using a Where Clause in the rastVal parameter |
| mask | BOOLEAN | FALSE | Whether to Mask the output. Mask will create an output with values of 1 where criteria met, within AOI. False will retain values from VAT |
| rastSize | NUMERIC | 100 | Size of output raster cells |
| rastPixType | VARCHAR | 32BF | Pixel type of output raster |
| noData | NUMERIC | 0 | No Data value |
| tile | BOOLEAN | False | Whether to tile the ouptut raster |
Usage & Examples:
Examples using a WKT Polygon for AOI
Generate an output raster with a WKT Polygon with no filtering output.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_AOI_MASK',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_TSA_EXTENT_RASTER',
mask:=TRUE
)Generate an output raster with a WKT Polygon retaining all values.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_AOI_RETAIN',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_TSA_EXTENT_RASTER'
)Generate an output raster with a WKT Polygon querying the VAT for ESSF and ICH zones and retaining source raster values.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_AOI_RETAIN_ESSFICH',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_TSA_EXTENT_RASTER',
rastVal:= 'ZONE IN (''ESSF'', ''ICH'') ',
rastVAT:= 'BEC_TSA_EXTENT_RASTER_VAT'
)Generate an output raster with a WKT Polygon querying the VAT for ESSF and ICH zones and masking.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_AOI_RETAIN_ESSFICH',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_TSA_EXTENT_RASTER',
rastVal:= 'ZONE IN (''ESSF'', ''ICH'') ',
rastVAT:= 'BEC_TSA_EXTENT_RASTER_VAT',
mask:=TRUE
)Generate an output raster with a WKT Polygon and retain all the values from the source raster within that area.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_AOI_RASTVALS_ALL',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_TSA_EXTENT_ZONEALL_RASTER',
rastVal:= '*',
mask:=FALSE
)Generate an output raster with a WKT Polygon and select for particular values and a range of values using the rastVAl parameter.
When querying for source raster values you can use individual values or a range of values.
Examples:
rastVal:= ’*’
rastVal:= ‘4, 8, 48’
rastVal:= ‘4, 8-10, 12, 30-35’
etc.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_AOI_RASTVALS_EX1',
'POLYGON((-118.473196412943 51.6955188330737,-118.982643618749 51.3438924145354,-118.444851411751 51.0748582423647,-117.985076049477 51.3973510159727,-118.473196412943 51.6955188330737))',
'BEC_TSA_EXTENT_ZONEALL_RASTER',
rastVal:= '4, 8, 30-50',
mask:=FALSE
)Generate an output raster using the geometry from another vector table as the area of interest. Masking the output. No query filter (rastVAl) applied.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_GEOM_MASK',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE '%OO%'),
'BEC_TSA_EXTENT_RASTER',
mask:=TRUE
)Generate an output raster using the geometry from another vector table as the area of interest. Retain source values in the output. No query filter (rastVal) applied.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_GEOM_RETAIN',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE '%OO%'),
'BEC_TSA_EXTENT_RASTER',
mask:=FALSE
)Generate an output raster using the geometry from another vector table as the area of interest. Retain source values in the output. Query for Zones ICH and ESSF using a related VAT.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_GEOM_RETAIN_ESSFICH',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE '%OO%'),
'BEC_TSA_EXTENT_RASTER',
mask:=FALSE,
rastVal:= 'ZONE IN (''ESSF'', ''ICH'') ',
rastVAT:= 'BEC_TSA_EXTENT_RASTER_VAT'
)Generate an output raster using the geometry from another vector table as the area of interest. Mask the values in the output. Query for Zones ICH and ESSF using a related VAT.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_GEOM_RETAIN_ESSFICH',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE '%OO%'),
'BEC_TSA_EXTENT_RASTER',
mask:=TRUE,
rastVal:= 'ZONE IN (''ESSF'', ''ICH'') ',
rastVAT:= 'BEC_TSA_EXTENT_RASTER_VAT'
)Generate an output raster using the geometry from another vector table as the area of interest. Mask the values in the output. Query for Zones ICH and ESSF using a related VAT.
SELECT FAIB_RASTER_FROM_RASTER(
'BEC_TSA_GEOM_RETAIN_RASTVALS',
(SELECT ST_UNION(WKB_GEOMETRY) FROM TSA_CLIP WHERE UPPER(TSA_NAME) LIKE '%OO%'),
'BEC_TSA_EXTENT_RASTER',
mask:=FALSE,
rastVal:= '1, 3, 8',
)